﻿using System;
using System.Collections.Generic;

using System.Text;

namespace Ecreate.Popedom.Dao.Hibernate
{
    public class GroupDaoImpl:IGroupDao
    {
        public IList<tGroup> getAll()
        {
            NHibernate.ISession s=Utility.getSession();
           
            return s.CreateQuery(" from tGroup t where 1=1 ").List<tGroup>();
        }



        public System.Collections.IList getSearchAll()
        {
            NHibernate.ISession s = Utility.getSession();
            return s.CreateQuery("select new List( Group.Groupname as Groupname,Id,Username) from tSysuser ").List();

         
        }



        public tGroup getByID(long id)
        {
            NHibernate.ISession s = Utility.getSession();
            return (tGroup)s.Load(typeof(tGroup), id);
        }


        public void UpdateMenusByGroupId(long Id, IList<tGroupassign> Menus)
        {
            NHibernate.ISession s = Utility.getSession();
            s.Transaction.Begin();
            tGroup group = (tGroup)s.Load(typeof(tGroup), Id);
            foreach (tGroupassign assign in group.Assigns)
            {
                s.Delete(assign);
            }
            group.Assigns = Menus;
            s.Save(group);
            s.Transaction.Commit();
        }
        public void InsertGroup(tGroup model)
        {
            NHibernate.ISession s = Utility.getSession();
            s.Transaction.Begin();
            s.Save(model);
            s.Transaction.Commit();
        }
        public void DeleteGroup(tGroup model)
        {
            NHibernate.ISession s = Utility.getSession();
            s.Transaction.Begin();
            s.Delete(model);
            s.Transaction.Commit();
        }
        public void UpdateGroup(tGroup model)
        {
            NHibernate.ISession s = Utility.getSession();
            s.Transaction.Begin();
            s.Clear();
            s.Update(model);
            s.Transaction.Commit();
        }



        public IList<tGroup> getAllZero()
        {
            NHibernate.ISession session = Utility.getSession();
            return session.CreateQuery(" from tGroup t  where t.Grouplevel.Flevel=0 and   1=1 ").List<tGroup>();
        }
        public IList<tGroup> getAllOne()
        {
            NHibernate.ISession session = Utility.getSession();
            return session.CreateQuery(" from tGroup t  where t.Grouplevel.Flevel=1 and   1=1  ").List<tGroup>();
        }
        public IList<tGroup> getAllTwo()
        {
            NHibernate.ISession session = Utility.getSession();
            return session.CreateQuery(" from tGroup t  where t.Grouplevel.Flevel=2 and   1=1  ").List<tGroup>();
        }

        public IList<tGroup> getAllThree()
        {
            NHibernate.ISession session = Utility.getSession();
            return session.CreateQuery(" from tGroup t  where t.Grouplevel.Flevel=3 and   1=1   ").List<tGroup>();
        }
    }
}
